<?php

/**
 * Instantiate a Slim app
 * http://docs.slimframework.com/#Hello-World
 * https://github.com/codeguy/Slim-Views
 */
$app = new \Slim\Slim(array(
    'view' => new \Slim\Views\Twig(),
    'debug' => true
));

/**
 * Initiate Twig
 */
$view = $app->view();
// path to twig
$view->parserDirectory = "../../twig/twig/lib/Twig";
// twig options
$view->parserOptions = array(
    'debug' => true
);
// enable helper functions
$view->parserExtensions = array(
    new \Slim\Views\TwigExtension(),
    new Twig_Extension_StringLoader()
);
// set the template directory
$view->setTemplatesDirectory("../backend/templates");

/**
 * Load all other files
 */
foreach (glob('../backend/app/*.php') as $filename) {
    require_once $filename;
}
// Models
foreach (glob('../backend/app/models/*.php') as $filename) {
    require_once $filename;
}

// Make a new connection
use Illuminate\Database\Capsule\Manager as Capsule;

if(file_exists("../backend/app/config/database.config.php")){
    $capsule = new Capsule;
    $capsule->addConnection(include '../backend/app/config/database.config.php');
    $capsule->bootEloquent();
    $capsule->setAsGlobal();
    
    $app->db = $capsule;
} else {
    die("<pre>database config not found</pre>");
}
